/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tuitionmanagement.DAO;

import tuitionmanagement.util.PassEncrypt;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import tuitionmanagement.util.DBUtil;
import java.sql.CallableStatement;
import tuitionmanagement.entity.StudentInfo;

/**
 *
 * @author Admin
 */
public class StudentInfoDAO {

    private Connection con;
    private PassEncrypt pe;
    private ResultSet rs;
    private CallableStatement cst;
    private PreparedStatement pst;
    private String lastError;
    private final String SQL_ReadStudentProfile;
    private final String SQL_ReadTuitionInfo;

    /** Creates a new instance of AccountDAO */
    public StudentInfoDAO() {
        con = null;
        pe = new PassEncrypt();
        rs = null;
        pst = null;
        lastError = "";
        SQL_ReadStudentProfile = "Select * from Student";
        SQL_ReadTuitionInfo = "SELECT FeeLevel.PaidTime, FeeLevel.MoneyToTal, [Order].Money FROM  FeeLevel CROSS JOIN  [Order] ";

    }

    /**
     * Get Account list
     * @return ArrayList<Account>
     */
    @SuppressWarnings("static-access")
    public ArrayList<StudentInfo> readByAll_StudentProfile() {
        ArrayList<StudentInfo> list = new ArrayList<StudentInfo>();
        con = DBUtil.getConn();
        try {
            pst = con.prepareStatement(SQL_ReadStudentProfile);
            rs = pst.executeQuery();
            while (rs.next()) {
                StudentInfo b = new StudentInfo();
                b.setStudentId(rs.getInt(1));
                b.setStudentName(rs.getString(2));
                b.setGender(rs.getString(3));
                b.setBirthday(rs.getDate(4));
                b.setAddress(rs.getNString(5));
                b.setPhone(rs.getString(6));
                b.setEmail(rs.getString(7));
                list.add(b);
            }
        } catch (SQLException ex) {
            setLastError(ex.getMessage());
        }
        return list;
    }
    public ArrayList<StudentInfo> readByAll_TuitionInfo() {
        ArrayList<StudentInfo> list = new ArrayList<StudentInfo>();
        con = DBUtil.getConn();
        try {
            pst = con.prepareStatement(SQL_ReadTuitionInfo);
            rs = pst.executeQuery();
            while (rs.next()) {
                StudentInfo b = new StudentInfo();
                b.setClassName(rs.getString(1));
                b.setMoneyTotal(rs.getInt(2));
                b.setPaidTimes(rs.getInt(3));
                b.setPaidMoney(rs.getInt(4));
                b.setDebtMoney(rs.getInt(5));
                list.add(b);
            }
        } catch (SQLException ex) {
            setLastError(ex.getMessage());
        }
        return list;
    }
    /**
     * @return the lastError
     */
    public String getLastError() {
        return lastError;
    }

    /**
     * @param lastError the lastError to set
     */
    public void setLastError(String lastError) {
        this.lastError = lastError;
    }
}
